﻿using System;

class SequenceOfOperators
{
    static void Main()
    {
        //Exercise 12.
        //We are given integer number n, value v (v=0 or 1) and a position p. Write a sequence of operators that modifies n 
        //to hold the value v at the position p from the binary representation of n.
        //Example: n = 5 (00000101), p=3, v=1 -> 13 (00001101)
        //n = 5 (00000101), p=2, v=0 -> 1 (00000001)

        Console.Write("Enter integer: ");
        int n = int.Parse(Console.ReadLine());
        Console.Write("Enter position: ");
        int p = int.Parse(Console.ReadLine());
        Console.Write("Enter value (0 or 1): ");
        int v = int.Parse(Console.ReadLine());
        Console.WriteLine(Convert.ToString(n,2).PadLeft(32,'0'));

        if (v == 1)
        {
            int mask = (1 << p);
            int midResult = n | mask;
            Console.WriteLine(midResult);
        }
        else 
        {
            int mask1 = ~(1 << p);
            int result = n & mask1;
            Console.WriteLine(result);
        }
    }
}

